#!/usr/bin/perl
#connectnv.cgi	Conn/Disconn a net volume1

require './lvm-lib.pl';
&ReadParse();
error_setup("error");

$sv = $in{'sv'};
$sv =~ /dev\/(vg\d)\/(\S+)/;
$svvg = $1;
$svname = $2;
$svname =~/^v(\d)snapshot/;
$originlv = "/dev/$svvg/volume$1"; 
$svpath = "/snapshot/".$svname;
$svdev = "/dev/mapper/".$svvg."-".$svname;
@svstat = vol_mount_status($svpath);

if($svstat[0]){

	`umount $svpath 2>/dev/null`;
	$rc = $?>>8;
	if($rc){
		$err_msg = $text{'err_sv_busy'};
		&error($err_msg);
	}
	`rm -rf $svpath`;
}
else{
	if(-e $svpath) {
	}
	else{
		`mkdir $svpath`;
		#`chmod -R a-w $svpath`;
	}
	`mount $sv $svpath 2>/dev/null`;
	$rc = $?>>8;
	$err_msg=$rc;
	if($rc){
		$err_msg = $text{'err_mount'};
		&error($err_msg);
	}
	`chmod 777 $svpath`;
}
&redirect("snapshot.cgi?lv=$originlv");
